// gulp 的入口文件

// exports.foo = done => {
//   console.log('foo task workinf~')

//   done() // 标识任务完成
// }

// exports.default = done => {
//   console.log('default task working~')

//   done()
// }

const fs = require('fs')

const { series, parallel } = require('gulp')

const task1 = done => {
  setTimeout(() => {
    console.log('task1 working~')
    done()
  }, 1000)
}

const task2 = done => {
  setTimeout(() => {
    console.log('task2 working~')
    done()
  }, 1000)
}

const task3 = done => {
  setTimeout(() => {
    console.log('task3 working~')
    done()
  }, 1000)
}

exports.foo = series(task1, task2, task3)  // 串行

exports.bar = parallel(task1, task2, task3) // 并行

exports.callback = done => {
  console.log('callback task~')
  done()
}

exports.callback_error = done => {
  console.log('callback taskz~')
  done(new Error('taks failed！'))
}

exports.promise = () => {
  console.log('promise task~')
  return Promise.resolve()
}

const timeout = time => {
  return new Promise(resolve => {
    setTimeout(resolve, time)
  })
}

exports.async = async () => {
  await timeout(1000)
  console.log('async task')
}

exports.stream = () => {
  const readStream = fs.createReadStream('package.json')
  const writeStream = fs.createWriteStream('temp.text')
  readStream.pipe(writeStream)
  return readStream
}



// const gulp = require('gulp')

// gulp.task('bar', done => {
//   console.log('default task working~')
//   done()
// })